package com.luckcoder.relax.games.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import com.luckcoder.relax.games.domain.vo.RelaxBlessingConfigVo;
import com.luckcoder.relax.games.domain.bo.RelaxBlessingConfigBo;
import com.luckcoder.relax.games.service.IRelaxBlessingConfigService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 祝福语配置
 *
 * @author zhanghao
 * @date 2025-09-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/relax/blessingConfig")
public class RelaxBlessingConfigController extends BaseController {

    private final IRelaxBlessingConfigService relaxBlessingConfigService;

    /**
     * 查询祝福语配置列表
     */
    @SaCheckPermission("relax:blessingConfig:list")
    @GetMapping("/list")
    public TableDataInfo<RelaxBlessingConfigVo> list(RelaxBlessingConfigBo bo, PageQuery pageQuery) {
        return relaxBlessingConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出祝福语配置列表
     */
    @SaCheckPermission("relax:blessingConfig:export")
    @Log(title = "祝福语配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(RelaxBlessingConfigBo bo, HttpServletResponse response) {
        List<RelaxBlessingConfigVo> list = relaxBlessingConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "祝福语配置", RelaxBlessingConfigVo.class, response);
    }

    /**
     * 获取祝福语配置详细信息
     *
     * @param blessingId 主键
     */
    @SaCheckPermission("relax:blessingConfig:query")
    @GetMapping("/{blessingId}")
    public R<RelaxBlessingConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long blessingId) {
        return R.ok(relaxBlessingConfigService.queryById(blessingId));
    }

    /**
     * 新增祝福语配置
     */
    @SaCheckPermission("relax:blessingConfig:add")
    @Log(title = "祝福语配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody RelaxBlessingConfigBo bo) {
        return toAjax(relaxBlessingConfigService.insertByBo(bo));
    }

    /**
     * 修改祝福语配置
     */
    @SaCheckPermission("relax:blessingConfig:edit")
    @Log(title = "祝福语配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody RelaxBlessingConfigBo bo) {
        return toAjax(relaxBlessingConfigService.updateByBo(bo));
    }

    /**
     * 删除祝福语配置
     *
     * @param blessingIds 主键串
     */
    @SaCheckPermission("relax:blessingConfig:remove")
    @Log(title = "祝福语配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{blessingIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] blessingIds) {
        return toAjax(relaxBlessingConfigService.deleteWithValidByIds(List.of(blessingIds), true));
    }
}
